package circle;

public class CircleQueue<E> {
	private int size;
	private E[] elements;
	private int front;
//	private int rear;

	@SuppressWarnings("unchecked")

	public CircleQueue() {
		elements = (E[]) new Object[10];
	}

	private int index(int index) {
		index = index + front;

		int newIndex = index - (index >= size ? size : 0);
		return newIndex;
	}

	public int size() {
		return size;
	}

	public boolean isEmpty() {
		return size == 0;
	}

	public void enQueue(E element) {
		elements[index(0)] = element;
		size++;
	}

	public E deQueue() {
		E e = elements[front];
		elements[front] = null;
		front = index(1);
		size--;
		return e;
	}

	public E front() {
		return elements[front];
	}

	public void clear() {
		for (int i = 0; i < elements.length; i++) {
			elements[i] = null;
		}
		size = 0;
		front = 0;
	}
}
